<template>
  <div class="question-edit-form">
    <el-form ref="form" :model="form" label-width="100px">
      <el-form-item label="题目分值">
        <el-input-number
          v-model="form.score"
          :min="0.5"
          :step="0.5"
          :precision="1"
        />
      </el-form-item>

      <el-form-item label="是否必做">
        <el-radio-group v-model="form.required">
          <el-radio :label="1">必做</el-radio>
          <el-radio :label="0">选做</el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="排序序号">
        <el-input-number
          v-model="form.sort"
          :min="1"
          :step="1"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="handleSave">保存</el-button>
        <el-button @click="$emit('cancel')">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'QuestionEditForm',
  props: {
    question: {
      type: Object,
      required: true
    },
    paperQuestion: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      form: {
        score: this.paperQuestion.score,
        required: this.paperQuestion.required,
        sort: this.paperQuestion.sort
      }
    }
  },
  methods: {
    handleSave() {
      const updatedQuestion = {
        ...this.question,
        ...this.form
      }
      this.$emit('save', updatedQuestion)
    }
  }
}
</script>

<style lang="scss" scoped>
.question-edit-form {
  padding: 20px;
}
</style>
